/**
 * Created by python on 18-11-14.
 */
/**
 * Created by python on 18-11-11.
 */
var aaa = new Vue({
    el:"#app",
    data:{
        // 页面中需要使用到的数据，键值对
        but1 : true,
        but2 : true,
        but3 : true,
        but4 : true,
        base ,
        user_id: sessionStorage.user_id || localStorage.user_id,
        token: sessionStorage.token || localStorage.token,
        username : "",
        school : "",
        city : "",
        company : "",
        eamil : "",
        password : "",
        mobile : "",
        personurl : "",
        introduction : "",
        create_time : "",
        like_count : "",
        content : [],
        title : "",
        a : {}

    },
    computed:{
        // 需要通过计算得到的数据，键值对 ，键是名称，值是匿名函数
    },
    mounted:function () {
        // 一加载就需要做的，直接是代码
        this.show_user_info();
        this.show_my_question();
    },
    methods:{

        // 需要用到的函数，键值对 ，键是名称，值是匿名函数
        show_user_info : function () {
            axios.get(this.base + '/userinfo/' + this.user_id + '/', {
               headers: {
                   'Authorization': 'JWT ' + this.token
                },
                responseType: 'json',
            })
                .then(response => {
                    // 加载用户数据
                    // console.log(response.data)

                    // this.user_id = response.data.id;
                    this.username = response.data.username;
                    this.city = response.data.city;
                    this.mobile = response.data.mobile;
                    this.email = response.data.email;
                    this.school = response.data.school;
                    this.company = response.data.company;
                    this.personurl = response.data.personurl;
                    this.introduction = response.data.introduction;

                })
                .catch(error => {
                    alert(error)
                })
        },
        show_my_question : function () {
            axios.get(this.base + '/usermyquestion/' + this.user_id + '/', {
                headers: {

                },
                responseType: 'json',
                })
                .then(response => {
                    this.content = response.data;


                })
                .catch(error => {
                    alert(error)
                })

            },
        show_city : function () {
            this.but1 = false
        },
        show_sch : function () {
            this.but2 = false
        },
        show_com : function () {
            this.but3 = false
        },
        show_url : function () {
            this.but4 = false
        },

        all_submit : function () {

            axios.patch(this.base + '/userinfoupdate/' + this.user_id + '/', {

                })
               .then(response => {
                   this.show_user_info()
                   this.but1 = false;
                   this.but2 = false;
                   this.but3 = false;
                   this.but4 = false;

               })
                .catch(

                )
        },
        // tz : function (id) {
        //     axios.get(this.base + '/question/' + id + '/', {
        //         headers: {
        //            'Authorization': 'JWT ' + this.token
        //         },
        //         responseType: 'json',
        //         })
        //         .then(response => {
        //             location.href = '/qa-detail.html'
        //         })
        // }




    }
});